<template>
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="nav-close"><i class="fa fa-times-circle"></i>
        </div>
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">
                <li class="nav-header">
                    <div class="dropdown profile-element" style="text-align: center;">
                        <span><img alt="image" class="img-circle" src="../assets/img/profile_small.jpg"/></span>
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear">
                                <span class="block m-t-xs"><strong class="font-bold">{{data.username}}</strong></span>
                                <span class="text-muted text-xs block">{{data.realName}}<b class="caret"></b></span>
                            </span>
                        </a>
                        <ul class="dropdown-menu animated fadeInRight m-t-xs">
                            <li><a class="J_menuItem" @click="linkTo('/setting/profile')">个人信息</a>
                            </li>
                            <li><a class="J_menuItem" @click="linkTo('/setting/reset')">重置密码</a>
                            </li>
                        </ul>
                    </div>
                </li>
                <li v-show="displayMenu(134)">
                    <a href="#">
                        <i :class="getMenuInfo(134).icon"></i>
                        <!--                        <span class="nav-label">主页</span>-->
                        <span class="nav-label">{{getMenuInfo(134).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level" v-show="displayMenu(138)">
                        <li>
                            <!--                            <a class="J_menuItem" @click="linkTo('/')">首页</a>-->
                            <a class="J_menuItem" @click="linkTo('/')">{{getMenuInfo(138).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(1)">
                    <a href="#">
                        <i :class="getMenuInfo(1).icon"></i>
                        <span class="nav-label">{{getMenuInfo(1).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(2)">
                            <a class="J_menuItem" @click="linkTo('/setting/manager_list')">{{getMenuInfo(2).name}}</a>
                        </li>
                        <!--                        <li>-->
                        <!--                            <a class="J_menuItem" @click="linkTo('/setting/character')">角色管理</a>-->
                        <!--                        </li>-->
                        <li v-show="displayMenu(77)">
                            <a class="J_menuItem" @click="linkTo('/setting/wechat_config')">{{getMenuInfo(77).name}}</a>
                        </li>
                        <li v-show="displayMenu(4)">
                            <a class="J_menuItem" @click="linkTo('/setting/menu_config')">{{getMenuInfo(4).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(64)">
                    <a href="#">
                        <i :class="getMenuInfo(64).icon"></i>
                        <span class="nav-label">{{getMenuInfo(64).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(66)">
                            <a class="J_menuItem"
                               @click="linkTo('/customer/customer_list')">{{getMenuInfo(66).name}}</a>
                        </li>
                        <li v-show="displayMenu(96)">
                            <a class="J_menuItem" @click="linkTo('/customer/store_list')">{{getMenuInfo(96).name}}</a>
                        </li>
                        <li v-show="displayMenu(113)">
                            <a class="J_menuItem" @click="linkTo('/customer/commucation')">{{getMenuInfo(113).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(61)">
                    <a href="#">
                        <i :class="getMenuInfo(61).icon"></i>
                        <span class="nav-label">{{getMenuInfo(61).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(41)">
                            <a class="J_menuItem" @click="linkTo('/product/product_list')">{{getMenuInfo(41).name}}</a>
                        </li>
                        <li v-show="displayMenu(36)">
                            <a class="J_menuItem"
                               @click="linkTo('/product/product_category')">{{getMenuInfo(36).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(62)">
                    <a href="#">
                        <i :class="getMenuInfo(62).icon"></i>
                        <span class="nav-label">{{getMenuInfo(62).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(51)">
                            <a class="J_menuItem" @click="linkTo('/order/order_list')">{{getMenuInfo(51).name}}</a>
                        </li>
                        <li v-show="displayMenu(118)">
                            <a class="J_menuItem"
                               @click="linkTo('/order/charge_back_list')">{{getMenuInfo(118).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(123)">
                    <a href="#">
                        <i :class="getMenuInfo(123).icon"></i>
                        <span class="nav-label">{{getMenuInfo(123).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(125)">
                            <a class="J_menuItem"
                               @click="linkTo('/groupbuy/groupbuy_list')">{{getMenuInfo(125).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(63)">
                    <a href="#">
                        <i :class="getMenuInfo(63).icon"></i>
                        <span class="nav-label">{{getMenuInfo(63).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(31)">
                            <a class="J_menuItem" @click="linkTo('/spread/spread_list')">{{getMenuInfo(31).name}}</a>
                        </li>
                        <li v-show="displayMenu(101)">
                            <a class="J_menuItem" @click="linkTo('/spread/coupon_list')">{{getMenuInfo(101).name}}</a>
                        </li>
                    </ul>
                </li>
                <li v-show="displayMenu(124)">
                    <a href="#">
                        <i :class="getMenuInfo(124).icon"></i>
                        <span class="nav-label">{{getMenuInfo(124).name}}</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li v-show="displayMenu(144)">
                            <a class="J_menuItem" @click="linkTo('/finance/dailyincome')">{{getMenuInfo(144).name}}</a>
                        </li>
                        <li v-show="displayMenu(145)">
                            <a href="#">{{getMenuInfo(145).name}} <span class="fa arrow"></span></a>
                            <ul class="nav nav-third-level">
                                <li v-show="displayMenu(146)">
                                    <a class="J_menuItem" @click="linkTo('/finance/analysis/groupbuy_analysis')">{{getMenuInfo(146).name}}</a>
                                </li>
                                <li v-show="displayMenu(147)">
                                    <a class="J_menuItem" @click="linkTo('/finance/analysis/order_analysis')">{{getMenuInfo(147).name}}</a>
                                </li>
                                <li v-show="displayMenu(148)">
                                    <a class="J_menuItem" @click="linkTo('/finance/analysis/charge_back_analysis')">{{getMenuInfo(148).name}}</a>
                                </li>
                                <!-- <li><a class="J_menuItem" @click="linkTo('/finance/analysis/sales_analysis')">销量统计</a>
                                </li> -->
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
</template>

<script>
    export default {
        name: 'LeftAside',
        data() {
            return {
                data: {
                    username: '',
                    email: '',
                    mobile: '',
                    realName: '',
                },
                menuList: [],
            }
        },
        mounted: function () {
            this.getUserInfo();

        },
        methods: {
            linkTo(toPath) {
                this.$router.push({
                    path: toPath
                });
            },
            async getUserInfo() {
                let res = await this.$api.get('/sys/user/info', {});
                if (res.code === 0) {
                    this.data = res.user;
                    this.$setCookie('userId', res.user.userId, 1270000)
                } else {
                    this.$message.error(res.msg);
                }
            },
            async getMenu() {
                let res = await this.$api.get('/sys/user/menu', {});
                if (res.code === 0) {
                    this.menuList = res.menu;
                } else {
                    this.$message.error(res.msg);
                }
            },
            displayMenu(id) {
                if (!this.$isEmptyArray(this.menuList)) {
                    for (let item of this.menuList) {
                        if (id === item.menuId) {
                            return true;

                        }
                    }

                }
                return false;
            },
            getMenuInfo(id) {
                if (!this.$isEmptyArray(this.menuList)) {
                    for (let item of this.menuList) {
                        if (id === item.menuId) {
                            return item;

                        }
                    }

                }
                return "";
            }
        },
        created() {
            this.getMenu();
        }
    }
</script>

<style>
</style>
